const express = require("express");
const app = express();
const cors = require("cors");

 app.use(express.json());
app.use(express.urlencoded({ extended: false })); 

//原生
app.use((req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Methods", "*");
  next();
});

app.get("/home", (req, res) => {
  res.send({ name: "get", data: [req.query] });
});

app.post("/add", (req, res) => {
  res.send({ name: "post", data: [req.body] });
});

app.delete("/delete", (req, res) => {
  res.send({ name: "delete", data: [req.body] });
});

app.put("/put", (req, res) => {
  res.send({ name: "put", data: [req.query] });
});

app.listen(8080, () => {
  console.log("8080 running");
});
